package com.leadingsoft.pwxk.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Component;

import com.leadingsoft.pwxk.model.UndoBaseInfo;
import com.leadingsoft.pwxk.repository.UndoBaseInfoRepository;
import com.leadingsoft.pwxk.services.AbstractService;

@Component
public class UndoBaseInfoServiceImpl extends AbstractService<UndoBaseInfo> {
	@Autowired
	UndoBaseInfoRepository undoBaseInfoRepository;

	@Override
	public void saveAll(List<UndoBaseInfo> models) {
		undoBaseInfoRepository.saveAll(models);
	}

	@Override
	public void deleteAll() {
		undoBaseInfoRepository.deleteAll();
	}

	@Override
	public void save(UndoBaseInfo model) {
		undoBaseInfoRepository.save(model);
	}

	@Override
	public String findLatestTime() {
		Sort sort = new Sort(Direction.DESC, "createtime");
		List<UndoBaseInfo> findAll = undoBaseInfoRepository.findAll(sort);
		if (!findAll.isEmpty() && findAll.size() > 0) {
			return findAll.get(0).getCreatetime();
		}
		return null;
	}
}
